//
//  LBSuperMarketDetailsBaseView.m
//  loveBeen
//
//  Created by 韩天助 on 11/20/16.
//  Copyright © 2016 loveBeen. All rights reserved.
//

#import "LBSuperMarketDetailsBaseView.h"
#import "LBSuperMarketHeaderView.h"

#define kHEADVIEWHEIGHT 384+77

@interface LBSuperMarketDetailsBaseView()<UITableViewDataSource,UITableViewDelegate>

@property(weak,nonatomic) LBSuperMarketHeaderView *headView;

@end

@implementation LBSuperMarketDetailsBaseView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (void)setProductModel:(LBSuperMarketProducts *)productModel{
    _productModel = productModel;

    self.headView.productModel = _productModel;


//    NSLog(@"%@",productModel);
}

- (instancetype)initWithProductModel:(LBSuperMarketProducts *)productModel{
    if (self = [super init]) {
        [self setUpUIWithProductModel:productModel];
    }
    return self;
}

//- (instancetype)init{
//    if (self = [super init]) {
//        
//        [self setUpUI];
//    }
//    return self;
//}

- (void)setUpUIWithProductModel:(LBSuperMarketProducts *)productModel{
    
    self.showsHorizontalScrollIndicator = NO;

    //MARK: headerView
    LBSuperMarketHeaderView *headView = [[LBSuperMarketHeaderView alloc]init];
    self.headView = headView;
    
//    headView.productModel = _productModel;
//    NSLog(@"%@",productModel);
    
    CGFloat headViewHeight = kHEADVIEWHEIGHT;
    
    //判断是否有优惠
    if (productModel.pm_desc.length > 0) {
        headViewHeight += 57;
    }
    
    //判断是否有品牌
    if (productModel.brand_name.length > 0) {
        headViewHeight += 57;
    }
    
    //判断是否有产品规格
    if (productModel.specifics.length > 0) {
        headViewHeight += 57;
    }
    
    //判断是否有保质期限
    if ([productModel.safe_day intValue] > 0) {
        headViewHeight += 57;
    }
    
    headView.frame = CGRectMake(0, 0, kScreenWidth, headViewHeight);
    
    self.tableHeaderView = headView;
    
    //MARK: footerView
    UIView *footView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 150)];
    
    UIImageView *footV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"v2_placeholder_full_size"]];
    
    footV.center = footView.center;
    
    [footView addSubview:footV];
    
    self.tableFooterView = footView;
    
    [self registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    
    self.dataSource = self;
    //    self.delegate = self;
    //
    self.rowHeight = 20;

    
}


//MARK: tableView的数据源方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    
    cell.backgroundColor = [UIColor lightGrayColor];
    
    return cell;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
@end
